package com.xuecheng.teaching.controller;

import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.dto.WorkChaDto;
import com.xuecheng.commons.model.dto.WorkDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.teaching.service.WorkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 作业前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class WorkController {

    @Autowired
    private WorkService  workService;

    //  分页条件查询课程计划作业列表
    @PostMapping("/work/list")
    public ResponseResult findByPage(PageRequest params, @RequestBody(required=false) WorkChaDto dto){
        return workService.findByPage(params, dto);
    }

    //新增或修改作业
    @PostMapping("/work")
    public ResponseResult saveOrUpdateWork(@RequestBody WorkDto dto){
        return workService.saveOrUpdateWork(dto);
    }

    //  根据id查询课程计划作业
    @GetMapping("/work/{workId}")
    public ResponseResult findById(@PathVariable("workId") Long workId){
        return workService.findById(workId);
    }

    //  删除课程计划的作业
    @DeleteMapping("/work/{workId}")
    public ResponseResult deleteById(@PathVariable("workId") Long workId){
        return workService.deleteById(workId);
    }




}
